<?php

declare (strict_types = 1);

namespace app\api\controller;

class Sms extends Base {

    public function sendCode() :object {
        $tel = $this->request->param("tel", "", "trim");
        try{
            $data = [
                "tel" => $tel
            ];
            validate(\app\api\validate\User::class)->scene("send_code")->check($data);
        }catch (\think\Exception\ValidateException $e){
            return show(config("status.error"), $e->getError());
        }

        if (\app\business\Sms::sendCode($tel)){;
            return show(config("status.success"), "发送成功", $data);
        }

        return show(config("status.error"), "发送失败");
    }
}